package edu.hunau.aop.handler;

import edu.hunau.aop.advice.TxManager;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author hb
 * @date 2022-11-29 11:38:19
 */
public class MyHandler  implements InvocationHandler {
    private Object target;//目标对象
    public void setTarget(Object target) {this.target = target;}

    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
        TxManager tx = new TxManager();//额外功能
        tx.beginTx();
        Object result = method.invoke(target, args);
        tx.commitTx();
        return result;}

}
